package cn.miju.admin.system.controller;

import cn.miju.admin.system.service.GroupService;
import cn.miju.admin.system.vo.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <pre>
 * 组织管理
 * </pre>
 *
 * @author zhuming
 * @version 1.0.0
 * @since 2023-04-04 16:10
 */
@RestController
@Api(tags = "系统-组织管理")
@ApiSort(5)
@RequestMapping("/system/group")
public class GroupController {
    private final GroupService service;

    public GroupController(GroupService service) {
        this.service = service;
    }

    /**
     * 组织分页查询
     * @param inVO {@link GroupPageInVO}
     * @return {@link Page<GroupPageOutVO>}
     */
    @ApiOperation("组织分页查询")
    @ApiOperationSupport(order = 1, author = "zhuming")
    @GetMapping(value = "/page")
    public Page<GroupPageOutVO> getPage(@ModelAttribute @Validated GroupPageInVO inVO) {
        return service.getPage(inVO);
    }
    /**
     * 一级组织树查询
     * @return {@link List<GroupTreeOutVO>}
     */
    @ApiOperation("一级组织树查询")
    @ApiOperationSupport(order = 2, author = "zhuming")
    @GetMapping(value = "/firstTree")
    public List<GroupTreeOutVO> getFirstTree() {
        return service.getFirstTree();
    }
    /**
     * 组织树查询
     * @return {@link List<GroupTreeOutVO>}
     */
    @ApiOperation("组织树查询")
    @ApiOperationSupport(order = 3, author = "zhuming")
    @GetMapping(value = "/tree")
    public List<GroupTreeOutVO> getTree() {
        return service.getTree();
    }

    /**
     * 保存
     * @param inVO {@link GroupSaveInVO}
     */
    @ApiOperation("保存")
    @ApiOperationSupport(order = 4, author = "zhuming")
    @PostMapping("/save")
    public void save(@RequestBody @Validated GroupSaveInVO inVO) {
        service.save(inVO);
    }

    /**
     * 批量删除
     * @param inVO {@link GroupDeleteInVO}
     */
    @ApiOperation("批量删除")
    @ApiOperationSupport(order = 5, author = "zhuming")
    @PostMapping("/deletes")
    public void deletes(@RequestBody @Validated GroupDeleteInVO inVO) {
        service.deletes(inVO);
    }
}
